package com.biz.aoao.mysql.mysqlbinlogsync.test;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.stream.Collectors;


@Slf4j
//@Component
@Data
public class MySmartInitializingSingleton implements SmartInitializingSingleton {

    @Autowired
    private DefaultListableBeanFactory defaultListableBeanFactory;

    private String name;

    /**
     * 表示在所有的bean实例化后，如果有bean实现了接口SmartInitializingSingleton，
     * 则会运行该实现类的afterSingletonsInstantiated方法
     */
    @Override
    public void afterSingletonsInstantiated() {

        log.info("afterSingletonsInstantiated ........");
        String[] beanDefinitionNames = defaultListableBeanFactory.getBeanDefinitionNames();
        Map<String, MySmartInitializingSingleton> beansOfType = defaultListableBeanFactory.getBeansOfType(MySmartInitializingSingleton.class);

        for(String name:beanDefinitionNames){
            System.out.println("beanName:"+name);
        }

    }
}
